package com.liu.susu.controller;

import com.liu.susu.pojo.Dog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Controller
@RequestMapping("/dog/jpqlAndEntityManager")
public class JpqlAndEntityManagerController {

    @PersistenceContext
    private EntityManager entityManager;

    @ResponseBody
    @RequestMapping("/list1")
    public List<Dog> getDogList(){
        List<Dog> dogList = entityManager.createNamedQuery("testNamedQuery")
                .getResultList();
        return dogList;
    }

}
